class Solution:
    def removeKdigits(self, num: str, k: int) -> str:
        if k >= len(num):
            return "0"
        i = 0
        while k and i < len(num) - 1:
            if num[i] > num[i + 1]:
                if i:
                    num = num[:i] + num[i + 1:]
                    i -= 1
                else:
                    num = num[1:]
                k -= 1
            else:
                i += 1
        if k:
            num = num[:-k]
        while num.startswith("0"):
            num = num[1:]
        return num if num else "0"


a = Solution()
print(a.removeKdigits(num="1432219", k=3))
print(a.removeKdigits(num="10200", k=1))
print(a.removeKdigits(num="10", k=2))
